package com.hwh.traffic.utils;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hwh.traffic.busEntity.BusDomJson;

import java.io.IOException;

public class BusInfoThead extends Thread{
    private String busApi;
    //通知接口
    private busInfoListener mBusInfoListener;
    private BusDomJson busInfo;
    private static ObjectMapper MAPPER = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    public BusInfoThead(String busApi){
        this.busApi = busApi;
    }

    public void setBusInfoListener(busInfoListener busInfoListener){
        mBusInfoListener = busInfoListener;
    }
    public String getBusApi() {
        return busApi;
    }
    //设置API接口
    public void setBusApi(String busApi) {
        this.busApi = busApi;
    }
    public BusDomJson getBusInfo() {
        return busInfo;
    }
    @Override
    public void run() {
        String busInfo_json = HttpUtil.httpGet(busApi);
        if (busInfo_json != null ){
            try {
                busInfo = MAPPER.readValue(busInfo_json, BusDomJson.class);
                //成功调用
                mBusInfoListener.getBusInfoSuccess();
            } catch (IOException e) {
                //失败调用
                mBusInfoListener.getBusInfoFail();
            }
        }
        else {
            mBusInfoListener.getBusInfoFail();
        }
    }
    public interface busInfoListener{
        void getBusInfoFail();
        void getBusInfoSuccess();
    }
}
